﻿using System;
using System.Collections.Generic;
using System.Text;

namespace System
{
    public class BaseBLL<T> : IBaseDAL<T>, IBaseBLL<T> where T : BaseModel, new()
    {
        public IBaseDAL<T> Instance;
        public BaseBLL()
        {
            Instance = DalFactory.CreateDAL<T>(DBType.Sql2005);
            if (!string.IsNullOrEmpty(ZConfig.ReadAppSettings("TimeOut")))
                Instance.TimeOut = Convert.ToInt32(ZConfig.ReadAppSettings("TimeOut"));
        }

        public bool IsLogicDelete;//标识是否逻辑删除，逻辑删除只是更新IsDelete字段

        public BaseBLL(DBType type)
        {
            Instance = DalFactory.CreateDAL<T>(type);
        }

        #region IBaseDAL<T> 成员

        public virtual int Add(T model, string fields)
        {
            return Instance.Add(model, fields);
        }

        public virtual int Add(List<T> list, string fields)
        {
            return Instance.Add(list, fields);
        }

        public virtual int Add(T model, string fields, string tableName)
        {
            return Instance.Add(model, fields, tableName);
        }

        public virtual int Add(List<T> list, string fields, string tableName)
        {
            return Instance.Add(list, fields, tableName);
        }

        public virtual int Remove(T model)
        {
            return Instance.Remove(model);
        }

        public virtual int Remove(List<T> list)
        {
            return Instance.Remove(list);
        }

        public virtual int Remove(string id)
        {
            return Instance.Remove(id);
        }

        public virtual int Remove(T model, string tableName)
        {
            return Instance.Remove(model, tableName);
        }

        public virtual int Remove(List<T> list, string tableName)
        {
            return Instance.Remove(list, tableName);
        }

        public virtual int Remove(string id, string tableName)
        {
            return Instance.Remove(id, tableName);
        }

        public virtual int Modify(T model, string fields)
        {
            return Instance.Modify(model, fields);
        }

        public virtual int Modify(List<T> list, string fields)
        {
            return Instance.Modify(list, fields);
        }

        public virtual int Modify(T model, string fields, string tableName)
        {
            return Instance.Modify(model, fields, tableName);
        }

        public virtual int Modify(List<T> list, string fields, string tableName)
        {
            return Instance.Modify(list, fields, tableName);
        }

        public virtual int AddOrModify(T model, string fields)
        {
            return Instance.AddOrModify(model, fields);
        }

        public virtual int AddOrModify(List<T> list, string fields)
        {
            return Instance.AddOrModify(list, fields);
        }

        public virtual int AddOrModify(T model, string fields, string tableName)
        {
            return Instance.AddOrModify(model, fields, tableName);
        }

        public virtual int AddOrModify(List<T> list, string fields, string tableName)
        {
            return Instance.AddOrModify(list, fields, tableName);
        }

        public virtual T GetModel(string fields, string filter, string sorts, string tableName, List<DBParameter> parameters)
        {
            return Instance.GetModel(fields, filter, sorts, tableName, parameters);
        }

        public virtual T GetModel(string id, string fields, string tableName)
        {
            return Instance.GetModel(id, fields, tableName);
        }

        public virtual T GetModel(List<DBParameter> parameters, string fields, string tableName)
        {
            return Instance.GetModel(parameters, fields, tableName);
        }

        public virtual T GetModel(string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetModel(fields, filter, sorts, parameters);
        }

        public virtual T GetModel(string id, string fields)
        {
            return Instance.GetModel(id, fields);
        }

        public virtual T GetModel(string id)
        {
            return Instance.GetModel(id);
        }

        public virtual T GetModel(List<DBParameter> parameters, string fields)
        {
            return Instance.GetModel(parameters, fields);
        }

        public virtual T GetModel(string sql, List<DBParameter> parameters)
        {
            return Instance.GetModel(sql, parameters);
        }

        public virtual List<T> GetList()
        {
            return Instance.GetList();
        }

        public virtual List<T> GetList(string sql, List<DBParameter> parameters)
        {
            return Instance.GetList(sql, parameters);
        }

        public virtual List<T> GetList(string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetList(fields, filter, sorts, parameters);
        }

        public virtual List<T> GetList(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetList(pageIndex, pageSize, ref recordCount, fields, filter, sorts, parameters);
        }

        public virtual List<T> GetList(string tableName)
        {
            return Instance.GetList(tableName);
        }

        public virtual List<T> GetList(string fields, string filter, string sorts, string tableName, List<DBParameter> parameters)
        {
            return Instance.GetList(fields, filter, sorts, tableName, parameters);
        }

        public virtual List<T> GetList(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, string tableName, List<DBParameter> parameters)
        {
            return Instance.GetList(pageIndex, pageSize, ref recordCount, fields, filter, sorts, tableName, parameters);
        }

        public virtual T GetModel(System.Data.IDataReader dr)
        {
            return Instance.GetModel(dr);
        }

        public virtual T GetModel(System.Data.DataRow dr)
        {
            return Instance.GetModel(dr);
        }

        public virtual T GetModel(System.Data.DataRowView dv)
        {
            return Instance.GetModel(dv);
        }

        public virtual List<T> GetList(System.Data.IDataReader dr)
        {
            return Instance.GetList(dr);
        }

        public virtual List<T> GetList(System.Data.DataTable dt)
        {
            return Instance.GetList(dt);
        }

        public virtual List<T> GetList(System.Data.DataView dv)
        {
            return Instance.GetList(dv);
        }

        public virtual T GetModel(SqlInfo sqlInfo, List<DBParameter> parameters)
        {
            return Instance.GetModel(sqlInfo, parameters);
        }

        public virtual List<T> GetList(SqlInfo sqlInfo, List<DBParameter> parameters)
        {
            return Instance.GetList(sqlInfo, parameters);
        }

        public virtual List<T> GetList(PageInfo pageInfo, List<DBParameter> parameters)
        {
            return Instance.GetList(pageInfo, parameters);
        }

        #endregion

        #region IBaseDal 成员

        public virtual string ModelAssemblyName
        {
            get
            {
                return Instance.ModelAssemblyName;
            }
            set
            {
                Instance.ModelAssemblyName = value;
            }
        }

        public virtual string ModelName
        {
            get
            {
                return Instance.ModelName;
            }
            set
            {
                Instance.ModelName = value;
            }
        }

        public virtual string TableName
        {
            get
            {
                return Instance.TableName;
            }
            set
            {
                Instance.TableName = value;
            }
        }

        public virtual Type ModelType
        {
            get { return Instance.ModelType; }
        }

        public virtual BaseModel BaseModel
        {
            get { return Instance.BaseModel; }
        }

        public virtual string PrimaryKey
        {
            get
            {
                return Instance.PrimaryKey;
            }
            set
            {
                Instance.PrimaryKey = value;
            }
        }

        public virtual bool Exists(string filter, List<DBParameter> parameters)
        {
            return Instance.Exists(filter, parameters);
        }

        public virtual int GetCount(string filter, List<DBParameter> parameters)
        {
            return Instance.GetCount(filter, parameters);
        }

        public virtual bool Exists(List<System.Data.Common.DbParameter> parameters, string filter)
        {
            return Instance.Exists(parameters, filter);
        }

        public virtual int GetCount(List<System.Data.Common.DbParameter> parameters, string filter)
        {
            return Instance.GetCount(parameters, filter);
        }

        public virtual int Delete(string filter, List<DBParameter> parameters)
        {
            return Instance.Delete(filter, parameters);
        }

        public virtual int Delete(DBParameter primaryKeyInfo)
        {
            return Instance.Delete(primaryKeyInfo);
        }

        public virtual int Delete(List<DBParameter> parameters)
        {
            return Instance.Delete(parameters);
        }

        public virtual int Delete(List<System.Data.Common.DbParameter> parameters, string filter)
        {
            return Instance.Delete(parameters, filter);
        }

        public virtual int Delete(List<System.Data.Common.DbParameter> parameters)
        {
            return Instance.Delete(parameters);
        }

        public virtual int Update(string fieldName, string filter, object value, List<DBParameter> parameters)
        {
            return Instance.Update(fieldName, filter, value, parameters);
        }

        public virtual int Update(List<System.Data.Common.DbParameter> parameters, string fieldName, string filter, object value)
        {
            return Instance.Update(parameters, fieldName, filter, value);
        }

        public virtual System.Data.DataTable GetDataTable(string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetDataTable(fields, filter, sorts, parameters);
        }

        public virtual System.Data.DataTable GetDataTable(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetDataTable(pageIndex, pageSize, ref recordCount, fields, filter, sorts, parameters);
        }

        public virtual System.Data.DataTable GetDataTable(List<System.Data.Common.DbParameter> parameters, string fields, string filter, string sorts)
        {
            return Instance.GetDataTable(parameters, fields, filter, sorts);
        }

        public virtual System.Data.DataTable GetDataTable(List<System.Data.Common.DbParameter> parameters, int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts)
        {
            return Instance.GetDataTable(parameters, pageIndex, pageSize, ref recordCount, fields, filter, sorts);
        }

        public virtual BaseModel GetObject(string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetObject(fields, filter, sorts, parameters);
        }

        public virtual BaseModel GetObject(string id, string fields)
        {
            return Instance.GetObject(id, fields);
        }

        public virtual BaseModel GetObject(string id)
        {
            return Instance.GetObject(id);
        }

        public virtual BaseModel GetObject(List<DBParameter> parameters, string fields)
        {
            return Instance.GetObject(parameters, fields);
        }

        public virtual BaseModel GetObject(string sql, List<DBParameter> parameters)
        {
            return Instance.GetObject(sql, parameters);
        }

        public virtual BaseModel GetObject(System.Data.IDataReader dr)
        {
            return Instance.GetObject(dr);
        }

        public virtual BaseModel GetObject(System.Data.DataRow dr)
        {
            return Instance.GetObject(dr);
        }

        public virtual BaseModel GetObject(System.Data.DataRowView drv)
        {
            return Instance.GetObject(drv);
        }

        public virtual System.Collections.ArrayList GetObjectList()
        {
            return Instance.GetObjectList();
        }

        public virtual System.Collections.ArrayList GetObjectList(System.Data.IDataReader dr)
        {
            return Instance.GetObjectList(dr);
        }

        public virtual System.Collections.ArrayList GetObjectList(System.Data.DataTable dt)
        {
            return Instance.GetObjectList(dt);
        }

        public virtual System.Collections.ArrayList GetObjectList(System.Data.DataView dv)
        {
            return Instance.GetObjectList(dv);
        }

        public virtual System.Collections.ArrayList GetObjectList(string sql, List<DBParameter> parameters)
        {
            return Instance.GetObjectList(sql, parameters);
        }

        public virtual System.Collections.ArrayList GetObjectList(string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetObjectList(fields, filter, sorts, parameters);
        }

        public virtual System.Collections.ArrayList GetObjectList(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetObjectList(pageIndex, pageSize, ref recordCount, fields, filter, sorts, parameters);
        }

        public virtual BaseModel GetObject(SqlInfo sqlInfo, List<DBParameter> parameters)
        {
            return Instance.GetObject(sqlInfo, parameters);
        }

        public virtual System.Collections.ArrayList GetObjectList(SqlInfo sqlInfo, List<DBParameter> parameters)
        {
            return Instance.GetObjectList(sqlInfo, parameters);
        }

        public virtual System.Collections.ArrayList GetObjectList(PageInfo pageInfo, List<DBParameter> parameters)
        {
            return Instance.GetObjectList(pageInfo, parameters);
        }

        public virtual int Delete(string id)
        {
            return Instance.Delete(id);
        }

        #endregion

        #region IDal 成员

        public virtual System.Data.Common.DbTransaction Transaction
        {
            get
            {
                return Instance.Transaction;
            }
            set
            {
                Instance.Transaction = value;
            }
        }

        public virtual Microsoft.Practices.EnterpriseLibrary.Data.Database DB
        {
            get
            {
                return Instance.DB;
            }
            set
            {
                Instance.DB = value;
            }
        }

        public virtual string ConfigName
        {
            get
            {
                return Instance.ConfigName;
            }
            set
            {
                Instance.ConfigName = value;
            }
        }

        public virtual LogUserInfo LogUser
        {
            get
            {
                return Instance.LogUser;
            }
            set
            {
                Instance.LogUser = value;
            }
        }

        public virtual DBType DBType
        {
            get { return Instance.DBType; }
        }

        public virtual int TimeOut { get { return Instance.TimeOut; } set { Instance.TimeOut = value; } }
        #endregion

        #region IDalExecute 成员

        public virtual int ExecuteNonQuery(string commandText)
        {
            return Instance.ExecuteNonQuery(commandText);
        }

        public virtual int ExecuteNonQuery(string commandText, System.Data.CommandType commandType)
        {
            return Instance.ExecuteNonQuery(commandText, commandType);
        }

        public virtual int ExecuteNonQuery(string commandText, List<System.Data.Common.DbParameter> parameters)
        {
            return Instance.ExecuteNonQuery(commandText, parameters);
        }

        public virtual int ExecuteNonQuery(string commandText, System.Data.CommandType commandType, List<System.Data.Common.DbParameter> parameters)
        {
            return Instance.ExecuteNonQuery(commandText, commandType, parameters);
        }

        public virtual object ExecuteScalar(string commandText)
        {
            return Instance.ExecuteScalar(commandText);
        }

        public virtual object ExecuteScalar(string commandText, System.Data.CommandType commandType)
        {
            return Instance.ExecuteScalar(commandText, commandType);
        }

        public virtual object ExecuteScalar(string commandText, List<System.Data.Common.DbParameter> parameters)
        {
            return Instance.ExecuteScalar(commandText, parameters);
        }

        public virtual object ExecuteScalar(string commandText, System.Data.CommandType commandType, List<System.Data.Common.DbParameter> parameters)
        {
            return Instance.ExecuteScalar(commandText, commandType, parameters);
        }

        public virtual System.Data.IDataReader ExecuteReader(string commandText)
        {
            return Instance.ExecuteReader(commandText);
        }

        public virtual System.Data.IDataReader ExecuteReader(string commandText, System.Data.CommandType commandType)
        {
            return Instance.ExecuteReader(commandText, commandType);
        }

        public virtual System.Data.IDataReader ExecuteReader(string commandText, List<System.Data.Common.DbParameter> parameters)
        {
            return Instance.ExecuteReader(commandText, parameters);
        }

        public virtual System.Data.IDataReader ExecuteReader(string commandText, System.Data.CommandType commandType, List<System.Data.Common.DbParameter> parameters)
        {
            return Instance.ExecuteReader(commandText, commandType, parameters);
        }

        public virtual System.Data.DataSet ExecuteDataSet(string commandText)
        {
            return Instance.ExecuteDataSet(commandText);
        }

        public virtual System.Data.DataSet ExecuteDataSet(string commandText, System.Data.CommandType commandType)
        {
            return Instance.ExecuteDataSet(commandText, commandType);
        }

        public virtual System.Data.DataSet ExecuteDataSet(string commandText, List<System.Data.Common.DbParameter> parameters)
        {
            return Instance.ExecuteDataSet(commandText, parameters);
        }

        public virtual System.Data.DataSet ExecuteDataSet(string commandText, System.Data.CommandType commandType, List<System.Data.Common.DbParameter> parameters)
        {
            return Instance.ExecuteDataSet(commandText, commandType, parameters);
        }

        public virtual int ExecuteNonQuery(string commandText, List<DBParameter> parameters, System.Data.CommandType commandType)
        {
            return Instance.ExecuteNonQuery(commandText, parameters, commandType);
        }

        public virtual object ExecuteScalar(string commandText, List<DBParameter> parameters, System.Data.CommandType commandType)
        {
            return Instance.ExecuteScalar(commandText, parameters, commandType);
        }

        public virtual System.Data.IDataReader ExecuteReader(string commandText, List<DBParameter> parameters, System.Data.CommandType commandType)
        {
            return Instance.ExecuteReader(commandText, parameters, commandType);
        }

        public virtual System.Data.DataSet ExecuteDataSet(string commandText, List<DBParameter> parameters, System.Data.CommandType commandType)
        {
            return Instance.ExecuteDataSet(commandText, parameters, commandType);
        }

        public virtual int ExecuteNonQuery(List<DBParameter> parameters, string commandText)
        {
            return Instance.ExecuteNonQuery(parameters, commandText);
        }

        public virtual object ExecuteScalar(List<DBParameter> parameters, string commandText)
        {
            return Instance.ExecuteScalar(parameters, commandText);
        }

        public virtual System.Data.IDataReader ExecuteReader(List<DBParameter> parameters, string commandText)
        {
            return Instance.ExecuteReader(parameters, commandText);
        }

        public virtual System.Data.DataSet ExecuteDataSet(List<DBParameter> parameters, string commandText)
        {
            return Instance.ExecuteDataSet(parameters, commandText);
        }

        public virtual System.Data.IDataReader ExecuteReader(string commandText, List<System.Data.Common.DbParameter> parameters, out System.Data.Common.DbParameterCollection outParameters)
        {
            return Instance.ExecuteReader(commandText, parameters, out outParameters);
        }

        public virtual System.Data.IDataReader ExecuteReader(string commandText, System.Data.CommandType commandType, List<System.Data.Common.DbParameter> parameters, out System.Data.Common.DbParameterCollection outParameters)
        {
            return Instance.ExecuteReader(commandText, commandType, parameters, out outParameters);
        }

        public virtual System.Data.IDataReader ExecuteReader(string commandText, List<DBParameter> parameters, System.Data.CommandType commandType, out System.Data.Common.DbParameterCollection outParameters)
        {
            return Instance.ExecuteReader(commandText, parameters, commandType, out outParameters);
        }

        public virtual System.Data.IDataReader ExecuteReader(List<DBParameter> parameters, string commandText, out System.Data.Common.DbParameterCollection outParameters)
        {
            return Instance.ExecuteReader(parameters, commandText, out outParameters);
        }

        #endregion

        #region IDalData 成员

        public virtual void OpenTransaction()
        {
            Instance.OpenTransaction();
        }

        public virtual bool Exists(string filter, string tableName, List<DBParameter> parameters)
        {
            return Instance.Exists(filter, tableName, parameters);
        }

        public virtual int GetCount(string filter, string tableName, List<DBParameter> parameters)
        {
            return Instance.GetCount(filter, tableName, parameters);
        }

        public virtual bool Exists(List<System.Data.Common.DbParameter> parameters, string filter, string tableName)
        {
            return Instance.Exists(parameters, filter, tableName);
        }

        public virtual int GetCount(List<System.Data.Common.DbParameter> parameters, string filter, string tableName)
        {
            return Instance.GetCount(parameters, filter, tableName);
        }

        public virtual int Delete(string filter, string tableName, List<DBParameter> parameters)
        {
            return Instance.Delete(filter, tableName, parameters);
        }

        public virtual int Delete(BaseModel model, string tableName)
        {
            return Instance.Delete(model, tableName);
        }

        public virtual int Delete(DBParameter primaryKeyInfo, string tableName)
        {
            return Instance.Delete(primaryKeyInfo, tableName);
        }

        public virtual int Delete(List<DBParameter> parameters, string tableName)
        {
            return Instance.Delete(parameters, tableName);
        }

        public virtual int Delete(System.Collections.ArrayList list, string tableName)
        {
            return Instance.Delete(list, tableName);
        }

        public virtual int Delete(List<System.Data.Common.DbParameter> parameters, string filter, string tableName)
        {
            return Instance.Delete(parameters, filter, tableName);
        }

        public virtual int Delete(string tableName, List<System.Data.Common.DbParameter> parameters)
        {
            return Instance.Delete(tableName, parameters);
        }

        public virtual int Update(string fieldName, string filter, string tableName, object value, List<DBParameter> parameters)
        {
            return Instance.Update(fieldName, filter, tableName, value, parameters);
        }

        public virtual int Update(BaseModel model, string fields, string tableName)
        {
            return Instance.Update(model, fields, tableName);
        }

        public virtual int Update(System.Collections.ArrayList list, string fields, string tableName)
        {
            return Instance.Update(list, fields, tableName);
        }

        public virtual int Update(BaseModel model, string fields, string filter, string tableName, List<DBParameter> parameters)
        {
            return Instance.Update(model, fields, filter, tableName, parameters);
        }

        public virtual int Update(List<System.Data.Common.DbParameter> parameters, string fieldName, string filter, string tableName, object value)
        {
            return Instance.Update(parameters, fieldName, filter, tableName, value);
        }

        public virtual int Update(List<System.Data.Common.DbParameter> parameters, BaseModel model, string fields, string filter, string tableName)
        {
            return Instance.Update(parameters, model, fields, filter, tableName);
        }

        public virtual System.Data.DataTable GetDataTable(string sql)
        {
            return Instance.GetDataTable(sql);
        }

        public virtual System.Data.DataTable GetDataTable(string sql, List<DBParameter> parameters)
        {
            return Instance.GetDataTable(sql, parameters);
        }

        public virtual System.Data.DataTable GetDataTable(string fields, string filter, string sorts, string tableName, List<DBParameter> parameters)
        {
            return Instance.GetDataTable(fields, filter, sorts, tableName, parameters);
        }

        public virtual System.Data.DataTable GetDataTable(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, string tableName, string primaryKey, List<DBParameter> parameters)
        {
            return Instance.GetDataTable(pageIndex, pageSize, ref recordCount, fields, filter, sorts, parameters);
        }

        public virtual System.Data.DataTable GetDataTable(List<System.Data.Common.DbParameter> parameters, string sql)
        {
            return Instance.GetDataTable(parameters, sql);
        }

        public virtual System.Data.DataTable GetDataTable(List<System.Data.Common.DbParameter> parameters, string fields, string filter, string sorts, string tableName)
        {
            return Instance.GetDataTable(parameters, fields, filter, sorts, tableName);
        }

        public virtual System.Data.DataTable GetDataTable(List<System.Data.Common.DbParameter> parameters, int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, string tableName, string primaryKey)
        {
            return Instance.GetDataTable(parameters, pageIndex, pageSize, ref recordCount, fields, filter, sorts, tableName, primaryKey);
        }

        public virtual System.Data.DataTable GetDataTable(SqlInfo sqlInfo, List<DBParameter> parameters)
        {
            return Instance.GetDataTable(sqlInfo, parameters);
        }

        public virtual System.Data.DataTable GetDataTable(PageInfo pageInfo, List<DBParameter> parameters)
        {
            return Instance.GetDataTable(pageInfo, parameters);
        }

        public virtual System.Data.DataTable GetDataTable(List<System.Data.Common.DbParameter> parameters, SqlInfo sqlInfo)
        {
            return Instance.GetDataTable(parameters, sqlInfo);
        }

        public virtual System.Data.DataTable GetDataTable(List<System.Data.Common.DbParameter> parameters, PageInfo pageInfo)
        {
            return Instance.GetDataTable(parameters, pageInfo);
        }

        public virtual int Insert(BaseModel model, string fields, string tableName)
        {
            return Instance.Insert(model, fields, tableName);
        }

        public virtual int Insert(System.Collections.ArrayList list, string fields, string tableName)
        {
            return Instance.Insert(list, fields, tableName);
        }

        public virtual int InsertOrUpdate(BaseModel model, string fields, string tableName)
        {
            return Instance.InsertOrUpdate(model, fields, tableName);
        }

        public virtual int InsertOrUpdate(System.Collections.ArrayList list, string fields, string tableName)
        {
            return Instance.InsertOrUpdate(list, fields, tableName);
        }

        public virtual int Delete(BaseModel model)
        {
            return Instance.Delete(model);
        }

        public virtual int Delete(System.Collections.ArrayList list)
        {
            return Instance.Delete(list);
        }

        public virtual int Insert(BaseModel model, string fields)
        {
            return Instance.Insert(model, fields);
        }

        public virtual int Insert(System.Collections.ArrayList list, string fields)
        {
            return Instance.Insert(list, fields);
        }

        public virtual int InsertOrUpdate(BaseModel model, string fields)
        {
            return Instance.InsertOrUpdate(model, fields);
        }

        public virtual int InsertOrUpdate(System.Collections.ArrayList list, string fields)
        {
            return Instance.InsertOrUpdate(list, fields);
        }

        public virtual int Update(BaseModel model, string fields)
        {
            return Instance.Update(model, fields);
        }

        public virtual int Update(System.Collections.ArrayList list, string fields)
        {
            return Instance.Update(list, fields);
        }

        public virtual int Update(BaseModel model, string fields, string filter, List<DBParameter> parameters)
        {
            return Instance.Update(model, fields, filter, parameters);
        }

        public virtual int Update(List<System.Data.Common.DbParameter> parameters, BaseModel model, string fields, string filter)
        {
            return Instance.Update(parameters, model, fields, filter);
        }

        #endregion

        #region ITM 成员

        public virtual int _Add<Tm>(Tm model, string fields) where Tm : BaseModel, new()
        {
            return Instance._Add<Tm>(model, fields);
        }

        public virtual int _Add<Tm>(List<Tm> list, string fields) where Tm : BaseModel, new()
        {
            return Instance._Add<Tm>(list, fields);
        }

        public virtual int _Add<Tm>(Tm model, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._Add<Tm>(model, fields, tableName);
        }

        public virtual int _Add<Tm>(List<Tm> list, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._Add<Tm>(list, fields, tableName);
        }

        public virtual int _Remove<Tm>(Tm model) where Tm : BaseModel, new()
        {
            return Instance._Remove<Tm>(model);
        }

        public virtual int _Remove<Tm>(List<Tm> list) where Tm : BaseModel, new()
        {
            return Instance._Remove<Tm>(list);
        }

        public virtual int _Remove<Tm>(string id) where Tm : BaseModel, new()
        {
            return Instance._Remove<Tm>(id);
        }

        public virtual int _Remove<Tm>(Tm model, string tableName) where Tm : BaseModel, new()
        {
            return Instance._Remove<Tm>(model, tableName);
        }

        public virtual int _Remove<Tm>(List<Tm> list, string tableName) where Tm : BaseModel, new()
        {
            return Instance._Remove<Tm>(list, tableName);
        }

        public virtual int _Remove<Tm>(string id, string tableName) where Tm : BaseModel, new()
        {
            return Instance._Remove<Tm>(id, tableName);
        }

        public virtual int _Modify<Tm>(Tm model, string fields) where Tm : BaseModel, new()
        {
            return Instance._Modify<Tm>(model, fields);
        }

        public virtual int _Modify<Tm>(List<Tm> list, string fields) where Tm : BaseModel, new()
        {
            return Instance._Modify<Tm>(list, fields);
        }

        public virtual int _Modify<Tm>(Tm model, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._Modify<Tm>(model, fields, tableName);
        }

        public virtual int _Modify<Tm>(List<Tm> list, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._Modify<Tm>(list, fields, tableName);
        }

        public virtual int _AddOrModify<Tm>(Tm model, string fields) where Tm : BaseModel, new()
        {
            return Instance._AddOrModify<Tm>(model, fields);
        }

        public virtual int _AddOrModify<Tm>(List<Tm> list, string fields) where Tm : BaseModel, new()
        {
            return Instance._AddOrModify<Tm>(list, fields);
        }

        public virtual int _AddOrModify<Tm>(Tm model, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._AddOrModify<Tm>(model, fields, tableName);
        }

        public virtual int _AddOrModify<Tm>(List<Tm> list, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._AddOrModify<Tm>(list, fields, tableName);
        }

        public virtual Tm _GetModel<Tm>(string fields, string filter, string sorts, string tableName, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(fields, filter, sorts, tableName, parameters);
        }

        public virtual Tm _GetModel<Tm>(string id, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(id, fields, tableName);
        }

        public virtual Tm _GetModel<Tm>(List<DBParameter> parameters, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(parameters, fields, tableName);
        }

        public virtual Tm _GetModel<Tm>(string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(fields, filter, sorts, parameters);
        }

        public virtual Tm _GetModel<Tm>(string id, string fields) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(id, fields);
        }

        public virtual Tm _GetModel<Tm>(string id) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(id);
        }

        public virtual Tm _GetModel<Tm>(List<DBParameter> parameters, string fields) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(parameters, fields);
        }

        public virtual Tm _GetModel<Tm>(string sql, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(sql, parameters);
        }

        public virtual List<Tm> _GetList<Tm>() where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>();
        }

        public virtual List<Tm> _GetList<Tm>(string sql, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>(sql, parameters);
        }

        public virtual List<Tm> _GetList<Tm>(string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>(fields, filter, sorts, parameters);
        }

        public virtual List<Tm> _GetList<Tm>(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>(pageIndex, pageSize, ref recordCount, fields, filter, sorts, parameters);
        }

        public virtual List<Tm> _GetList<Tm>(string tableName) where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>(tableName);
        }

        public virtual List<Tm> _GetList<Tm>(string fields, string filter, string sorts, string tableName, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>(fields, filter, sorts, tableName, parameters);
        }

        public virtual List<Tm> _GetList<Tm>(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, string tableName, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>(pageIndex, pageSize, ref recordCount, fields, filter,sorts, tableName, parameters);
        }

        public virtual Tm _GetModel<Tm>(System.Data.IDataReader dr) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(dr);
        }

        public virtual Tm _GetModel<Tm>(System.Data.DataRow dr) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(dr);
        }

        public virtual Tm _GetModel<Tm>(System.Data.DataRowView dv) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(dv);
        }

        public virtual List<Tm> _GetList<Tm>(System.Data.IDataReader dr) where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>(dr);
        }

        public virtual List<Tm> _GetList<Tm>(System.Data.DataTable dt) where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>(dt);
        }

        public virtual List<Tm> _GetList<Tm>(System.Data.DataView dv) where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>(dv);
        }

        public virtual Tm _GetModel<Tm>(SqlInfo sqlInfo, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetModel<Tm>(sqlInfo, parameters);
        }

        public virtual List<Tm> _GetList<Tm>(SqlInfo sqlInfo, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>(sqlInfo, parameters);
        }

        public virtual List<Tm> _GetList<Tm>(PageInfo pageInfo, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetList<Tm>(pageInfo, parameters);
        }

        #endregion

        #region IDisposable 成员

        public virtual void Dispose()
        {
            Instance.Dispose();
        }

        #endregion

        #region IEDal 成员

        public virtual int Delete(System.Collections.Hashtable list)
        {
            return Instance.Delete(list);
        }

        public virtual int Delete(System.Collections.Hashtable list, string tableName)
        {
            return Instance.Delete(list, tableName);
        }

        public virtual int Insert(System.Collections.Hashtable list, string fields)
        {
            return Instance.Insert(list, fields);
        }

        public virtual int Insert(System.Collections.Hashtable list, string fields, string tableName)
        {
            return Instance.Insert(list, fields, tableName);
        }

        public virtual int InsertOrUpdate(System.Collections.Hashtable list, string fields)
        {
            return Instance.InsertOrUpdate(list, fields);
        }

        public virtual int InsertOrUpdate(System.Collections.Hashtable list, string fields, string tableName)
        {
            return Instance.InsertOrUpdate(list, fields, tableName);
        }

        public virtual int Update(System.Collections.Hashtable list, string fields)
        {
            return Instance.Update(list, fields);
        }

        public virtual int Update(System.Collections.Hashtable list, string fields, string tableName)
        {
            return Instance.Update(list, fields, tableName);
        }

        #endregion

        #region IEBaseDal 成员

        public virtual System.Collections.Hashtable GetObjectHash()
        {
            return Instance.GetObjectHash();
        }

        public virtual System.Collections.Hashtable GetObjectHash(System.Data.IDataReader dr)
        {
            return Instance.GetObjectHash(dr);
        }

        public virtual System.Collections.Hashtable GetObjectHash(System.Data.DataTable dt)
        {
            return Instance.GetObjectHash(dt);
        }

        public virtual System.Collections.Hashtable GetObjectHash(System.Data.DataView dv)
        {
            return Instance.GetObjectHash(dv);
        }

        public virtual System.Collections.Hashtable GetObjectHash(string sql, List<DBParameter> parameters)
        {
            return Instance.GetObjectHash(sql, parameters);
        }

        public virtual System.Collections.Hashtable GetObjectHash(string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetObjectHash(fields, filter, sorts, parameters);
        }

        public virtual System.Collections.Hashtable GetObjectHash(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetObjectHash(pageIndex, pageSize, ref recordCount, fields, filter, sorts, parameters);
        }

        public virtual System.Collections.Hashtable GetObjectHash(SqlInfo sqlInfo, List<DBParameter> parameters)
        {
            return Instance.GetObjectHash(sqlInfo, parameters);
        }

        public virtual System.Collections.Hashtable GetObjectHash(PageInfo pageInfo, List<DBParameter> parameters)
        {
            return Instance.GetObjectHash(pageInfo, parameters);
        }

        #endregion

        #region IEBaseDAL<T> 成员

        public virtual int Add(Dictionary<string, T> list, string fields)
        {
            return Instance.Add(list, fields);
        }

        public virtual int Add(Dictionary<string, T> list, string fields, string tableName)
        {
            return Instance.Add(list, fields, tableName);
        }

        public virtual int AddOrModify(Dictionary<string, T> list, string fields)
        {
            return Instance.AddOrModify(list, fields);
        }

        public virtual int AddOrModify(Dictionary<string, T> list, string fields, string tableName)
        {
            return Instance.AddOrModify(list, fields, tableName);
        }

        public virtual Dictionary<string, T> GetDicList()
        {
            return Instance.GetDicList();
        }

        public virtual Dictionary<string, T> GetDicList(string sql, List<DBParameter> parameters)
        {
            return Instance.GetDicList(sql, parameters);
        }

        public virtual Dictionary<string, T> GetDicList(string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetDicList(fields, filter, sorts, parameters);
        }

        public virtual Dictionary<string, T> GetDicList(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetDicList(pageIndex, pageSize, ref recordCount, fields, filter, sorts, parameters);
        }

        public virtual Dictionary<string, T> GetDicList(string tableName)
        {
            return Instance.GetDicList(tableName);
        }

        public virtual Dictionary<string, T> GetDicList(string fields, string filter, string sorts, string tableName, List<DBParameter> parameters)
        {
            return Instance.GetDicList(fields, filter, sorts, tableName, parameters);
        }

        public virtual Dictionary<string, T> GetDicList(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, string tableName, List<DBParameter> parameters)
        {
            return Instance.GetDicList(pageIndex, pageSize, ref recordCount, fields, filter, sorts, tableName, parameters);
        }

        public virtual int Modify(Dictionary<string, T> list, string fields)
        {
            return Instance.Modify(list, fields);
        }

        public virtual int Modify(Dictionary<string, T> list, string fields, string tableName)
        {
            return Instance.Modify(list, fields, tableName);
        }

        public virtual int Remove(Dictionary<string, T> list)
        {
            return Instance.Remove(list);
        }

        public virtual int Remove(Dictionary<string, T> list, string tableName)
        {
            return Instance.Remove(list, tableName);
        }

        #endregion

        #region IEDal 成员


        public virtual int _Add<Tm>(Dictionary<string, Tm> list, string fields) where Tm : BaseModel, new()
        {
            return Instance._Add<Tm>(list, fields);
        }

        public virtual int _Add<Tm>(Dictionary<string, Tm> list, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._Add<Tm>(list, fields, tableName);
        }

        public virtual int _Remove<Tm>(Dictionary<string, Tm> list) where Tm : BaseModel, new()
        {
            return Instance._Remove<Tm>(list);
        }

        public virtual int _Remove<Tm>(Dictionary<string, Tm> list, string tableName) where Tm : BaseModel, new()
        {
            return Instance._Remove<Tm>(list, tableName);
        }

        public virtual int _Modify<Tm>(Dictionary<string, Tm> list, string fields) where Tm : BaseModel, new()
        {
            return Instance._Modify<Tm>(list, fields);
        }

        public virtual int _Modify<Tm>(Dictionary<string, Tm> list, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._Modify<Tm>(list, fields, tableName);
        }

        public virtual int _AddOrModify<Tm>(Dictionary<string, Tm> list, string fields) where Tm : BaseModel, new()
        {
            return Instance._AddOrModify<Tm>(list, fields);
        }

        public virtual int _AddOrModify<Tm>(Dictionary<string, Tm> list, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._AddOrModify<Tm>(list, fields, tableName);
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>() where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>();
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>(string sql, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>(sql, parameters);
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>(string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>(fields, filter, sorts, parameters);
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>(pageIndex, pageSize, ref recordCount, fields, filter, sorts, parameters);
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>(string tableName) where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>(tableName);
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>(string fields, string filter, string sorts, string tableName, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>(fields, filter, tableName, parameters);
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string filter, string sorts, string tableName, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>(pageIndex, pageSize, ref recordCount, fields, filter, sorts, parameters);
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>(System.Data.IDataReader dr) where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>(dr);
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>(System.Data.DataTable dt) where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>(dt);
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>(System.Data.DataView dv) where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>(dv);
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>(SqlInfo sqlInfo, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>(sqlInfo, parameters);
        }

        public virtual Dictionary<string, Tm> _GetDicList<Tm>(PageInfo pageInfo, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetDicList<Tm>(pageInfo, parameters);
        }

        #endregion

        #region IBaseBLL 成员

        public virtual List<T> GetListBySearch(int? pageIndex, int? pageSize, ref int? recordCount, string fields, string sorts, List<DBParameter> parameters)
        {
            throw new NotImplementedException("业务接口未实现!"); 
        }

        public virtual int AddInfo<T1, T2, T3>(T t, T1 t1, T2 t2, T3 t3, string fields)
        {
            throw new NotImplementedException("业务接口未实现!");
        }

        public bool ExistsKey(List<DBParameter> parameters, string key)
        {
            if (parameters == null || string.IsNullOrEmpty(key))
                return false;

            try
            {
                return parameters.Exists(delegate(DBParameter parameter) { return parameter.Value != null && parameter.ParameterName.ToUpper() == key.ToUpper(); });
            }
            catch (ArgumentNullException)
            {
                return false;
            }
        }

        public DBParameter FindDBParameter(List<DBParameter> parameters, string key)
        {
            if (parameters == null || string.IsNullOrEmpty(key))
                return null;

            return parameters.Find(delegate(DBParameter parameter) { return parameter.Value != null && parameter.ParameterName.ToUpper() == key.ToUpper(); });
        }
        #endregion

        public virtual void OnFieldSetting(string fieldName, object fieldValue)
        {
           
        }

        public virtual void OnFieldSetted(string fieldName, object fieldValue)
        {
          
        }


        public List<T> GetTop(int count)
        {
            return Instance.GetTop(count);
        }

        public List<T> GetTop(int count, string sorts)
        {
            return Instance.GetTop(count, sorts);
        }

        public List<T> GetTop(int count, string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetTop(count,fields, filter, sorts, parameters);
        }

        public List<T> GetTop(string tableName, int count)
        {
            return Instance.GetTop(tableName,count);
        }

        public List<T> GetTop(string tableName, int count, string sorts)
        {
            return Instance.GetTop(tableName, count, sorts);
        }

        public List<T> GetTop(string tableName, int count, string fields, string filter, string sorts, List<DBParameter> parameters)
        {
            return Instance.GetTop(tableName, count, fields, filter, sorts, parameters);
        }


        public List<Tm> _GetTop<Tm>(int count) where Tm : BaseModel, new()
        {
            return Instance._GetTop<Tm>(count);
        }

        public List<Tm> _GetTop<Tm>(int count, string sorts) where Tm : BaseModel, new()
        {
            return Instance._GetTop<Tm>(count, sorts);
        }

        public List<Tm> _GetTop<Tm>(int count, string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetTop<Tm>(count, fields, filter, sorts, parameters);
        }

        public List<Tm> _GetTop<Tm>(string tableName, int count) where Tm : BaseModel, new()
        {
            return Instance._GetTop<Tm>(tableName,count);
        }

        public List<Tm> _GetTop<Tm>(string tableName, int count, string sorts) where Tm : BaseModel, new()
        {
            return Instance._GetTop<Tm>(tableName, count, sorts);
        }

        public List<Tm> _GetTop<Tm>(string tableName, int count, string fields, string filter, string sorts, List<DBParameter> parameters) where Tm : BaseModel, new()
        {
            return Instance._GetTop<Tm>(tableName, count, fields, filter, sorts, parameters);
        }


        public int InsertOrUpdateBySQL(T model)
        {
            return Instance.InsertOrUpdateBySQL(model);
        }

        public int InsertOrUpdateBySQL(List<T> list)
        {
            return Instance.InsertOrUpdateBySQL(list);
        }

        public int InsertOrUpdateBySQL(T model, string fields)
        {
            return Instance.InsertOrUpdateBySQL(model, fields);
        }

        public int InsertOrUpdateBySQL(List<T> list, string fields)
        {
            return Instance.InsertOrUpdateBySQL(list, fields);
        }

        public int InsertOrUpdateBySQL(T model, string fields, string tableName)
        {
            return Instance.InsertOrUpdateBySQL(model,fields, tableName);
        }

        public int InsertOrUpdateBySQL(List<T> list, string fields, string tableName)
        {
            return Instance.InsertOrUpdateBySQL(list, fields, tableName);
        }


        public int _InsertOrUpdateBySQL<Tm>(Tm model) where Tm : BaseModel, new()
        {
            return Instance._InsertOrUpdateBySQL(model);
        }

        public int _InsertOrUpdateBySQL<Tm>(List<Tm> list) where Tm : BaseModel, new()
        {
            return Instance._InsertOrUpdateBySQL(list);
        }

        public int _InsertOrUpdateBySQL<Tm>(Tm model, string fields) where Tm : BaseModel, new()
        {
            return Instance._InsertOrUpdateBySQL(model, fields);
        }

        public int _InsertOrUpdateBySQL<Tm>(List<Tm> list, string fields) where Tm : BaseModel, new()
        {
            return Instance._InsertOrUpdateBySQL(list, fields);
        }

        public int _InsertOrUpdateBySQL<Tm>(Tm model, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._InsertOrUpdateBySQL(model, fields, tableName);
        }

        public int _InsertOrUpdateBySQL<Tm>(List<Tm> list, string fields, string tableName) where Tm : BaseModel, new()
        {
            return Instance._InsertOrUpdateBySQL(list, fields, tableName);
        }
    }
}
